package kyssion.leetcode.num151_200;

public class code165_比较版本号 {

    public static void main(String[] args) {
        System.out.println(new code165_比较版本号().compareVersion(
                "1", "1.1"
        ));
    }

    public int compareVersion(String version1, String version2) {
        String[] one = version1.split("\\.");
        String[] two = version2.split("\\.");
        int i = 0;
        while (true) {
            if (i >= one.length && i >= two.length) {
                return 0;
            } else if (i >= one.length) {
                if (Integer.valueOf(two[i]) != 0) {
                    return -1;
                } else {
                    i++;
                }
            } else if (i >= two.length) {
                if (Integer.valueOf(one[i]) != 0) {
                    return 1;
                } else {
                    i++;
                }
            } else {
                if (Integer.valueOf(one[i]) > Integer.valueOf(two[i])) {
                    return 1;
                } else if (Integer.valueOf(one[i]) < Integer.valueOf(two[i])) {
                    return -1;
                } else {
                    i++;
                }
            }
        }
    }
}
